<?php

use yii\helpers\Html;
use yii\widgets\DetailView;
use common\models\Product;
use common\models\CouponCategory;

/* @var $this yii\web\View */
/* @var $model common\models\Groupbuy */

$this->title = '查看拼团状态';
$this->params['breadcrumbs'][] = ['label' => 'Groupbuys', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="groupbuy-view">

    <h1><?= Html::encode($this->title) ?></h1>



    <?= DetailView::widget([
        'model' => $model,
        'attributes' => [
            'id',
//            'user1',
             ['attribute'=>'users','label'=>'用户名','format'=>'raw','value'=>function($model){
                $result='';
                $users= json_decode($model->users,true);
                foreach($users as $user){

                    $result.=$user['nickname'].'，';
                }
                return $result;
            }],
            ['attribute'=>'users','label'=>'手机号','format'=>'raw','value'=>function($model){
                $result='';
                $users= json_decode($model->users,true);
                foreach($users as $user){

                    $result.=$user['phone'].'，';
                }
                return $result;
            }],

            'createtime',
            'endtime',
            ['attribute'=>'goodsid','label'=>'拼团商品','value'=>function($model){
                return Product::findOne($model->goodsid)->name;
            }],
            ['attribute'=>'goodsid','label'=>'拼团优惠券','value'=>function($model){
                 $product=Product::findOne($model->goodsid);
                 $coupon_id=$product->coupon_id;
                 return CouponCategory::findOne($coupon_id)->title;
            }],
            ['attribute'=>'status','value'=>function($model){
                return $model->status?'拼团成功':'拼团中';
            }],
        ],
    ]) ?>
    <?=Html::button("返回列表",['onclick'=>'window.history.go(-1)','class'=>'btn btn-success'])?>

</div>
